<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Dettaglio utente</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="../../css/main.css" rel="stylesheet" />
<script type="text/javascript" src="../../js/prototype.js"></script>
<script type="text/javascript" src="../../js/scriptaculous.js"></script>
<script type="text/javascript" src="../../js/controls.js"></script>
<script type="text/javascript" src="../../js/page.js"></script>
<script type="text/javaScript">
var timeout;
var msg;
function go(par, user){
    if(par == 2){
        if(!confirm("Sei sicuro di voler cancellare questo utente?"))
            return false;
    }
    if(par == 1){
    	if(trim(document.forms[0].pwd.value) != trim(document.forms[0].pwd2.value)){
    		alert("Le password inserite sono differenti. Ricontrolla.");
    		return false;
    	}
    	document.forms[0].pwd.value = hex_md5(document.forms[0].pwd.value);
    	// fake password
    	document.forms[0].pwd2.value = "calatafimi";
    }
    $('_i').value = user;
    $('action').value = par;
    var url = "<?php print $_SESSION['__config__']['root_site'] ?>admin/adm_users/users_manager.php";
	var req = new Ajax.Request(url,
			  {
			    	method:'post',
			    	parameters: $('user_form').serialize(true),
			    	onSuccess: function(transport){
			      		var response = transport.responseText || "no response text";
			      		//alert(response);
			      		var dati = response.split("|");
			      		if(dati[0] == "ko"){
							alert("Errore SQL. \nQuery: "+dati[1]+"\nErrore: "+dati[2]);
							parent.win.close();
							return;
			      		}
			      		parent.win.close();
			      		link = "users.php?msg="+par;
			      		if(par != 1){
							link += "&second=1&offset=<?php print $offset ?>";
			      		}

						parent.document.location.href = link;
			    	},
			    	onFailure: function(){ alert("Si e' verificato un errore..."); }
			  });
}
	 
</script>
</head>
<body style="background-color: #FFFFFF">
    <p class="popup_header">Gestione utenti</p>
    <form action="dettaglio_utente.php?upd=1&offset=<?php print $offset ?>" method="post" id="user_form">
    <div style="text-align: center; width: 100%; margin: auto; ">
    <fieldset style="background: #f4f4f4; margin-right: auto; margin-left: auto; margin-bottom: 20px; padding-bottom: 20px; width: 550px; border: 1px solid; padding-top: 10px; <?php if(isset($_GET['id']) && $_GET['id'] != 0) print('display: none') ?>">
    <legend>Account</legend>
    <table style="margin: auto; width: 530px">
        <tr class="popup_row header_row">
            <td class="popup_title" style="width: 150px">UserName</td>
            <td style="width: 380px">
                <input class="form_input" type="text" name="uname" style="width: 380px" value="" <?php if(isset($user)) print("readonly='readonly'") ?> />
            </td>
        </tr>
        <tr class="popup_row">
            <td class="popup_title" style="width: 150px">Password</td>
            <td style="width: 380px">
                <input class="form_input" type="password" name="pwd" style="width: 380px" value="" <?php if(isset($user)) print("readonly='readonly'") ?> />
            </td>
        </tr>
        <tr class="popup_row">
            <td class="popup_title" style="width: 150px">Ripeti Password</td>
            <td style="width: 380px">
                <input class="form_input" type="password" name="pwd2" style="width: 380px" value="" <?php if(isset($user)) print("readonly='readonly'") ?> />
            </td>
        </tr>
    </table>
    </fieldset>
    <fieldset style="background: #f4f4f4; width: 550px; border: 1px solid; padding-top: 10px; margin: auto; padding-bottom: 20px; ">
    <legend>Dati personali</legend>
    <table style="width: 530px; margin: auto">
        <tr class="popup_row header_row">
            <td class="popup_title" style="width: 150px">Nome</td>
            <td style="width: 380px">
                <input class="form_input" type="text" name="nome" style="width: 380px" value="<?php if(isset($user)) print($user['nome']) ?>" />
            </td>
        </tr>
        <tr class="popup_row">
            <td class="popup_title" style="width: 150px">Cognome</td>
            <td style="width: 380px">
                <input class="form_input" type="text" name="cognome" style="width: 380px" value="<?php if(isset($user)) print($user['cognome']) ?>" />
            </td>
        </tr>
    </table>
    </fieldset>
    <fieldset style="background: #f4f4f4; margin-right: auto; margin-left: auto; width: 550px; border: 1px solid; padding-top: 20px; padding-bottom: 20px; margin-bottom: 30px; margin-top: 20px">
    <legend style="">Gruppi</legend>
    <table style="width: 530px">
        <tr class="popup_row header_row _center">
            <td colspan="2">
                <?php
                while($gr = $res_g->fetch_assoc()){
                    $checked = "";
                    if(isset($_GET['id']) && $_GET['id'] != 0){
                        if(in_array($gr['gid'], $gruppi_utente))
                        //if($user['gruppi']&$gr['codice'])
                            $checked = "checked";
                    }
                ?>
                <input type="checkbox" style="margin: auto" value="<?php print $gr['gid'] ?>" name="gruppi[]" <?php print $checked ?> />&nbsp;&nbsp;&nbsp;<?php print $gr['nome'] ?>&nbsp;&nbsp;&nbsp;
                <?php } ?>
                <input type="hidden" name="action" id="action" />
    			<input type="hidden" name="_i" id="_i" />
            </td>
        </tr>
    </table>
    </fieldset>
    </div>
    <div style="width: 575px; margin-right: 0px; text-align: right">
        <a href="#" onclick="go(<?php if(isset($_GET['id']) && $_GET['id'] != 0) print("3, ".$_REQUEST['id']); else print("1, 0"); ?>)" class="nav_link_first">Registra</a>|
        <?php if(isset($_GET['id']) && $_GET['id'] != 0){
        ?>
        <a href="#" onclick="go(2, <?php print $_REQUEST['id'] ?>)" class="nav_link">Cancella utente</a>|
        <?php
        }
        ?>
        <a href="#" onclick="parent.win.close()" class="nav_link_last">Chiudi</a>
    </div>
   </form>
</body>
</html>